<?php

namespace app\api\controller;

use app\common\controller\Api;
use Carbon\Carbon;

/**
 * 首页接口
 */
class Promotion extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function list()
    {
        $all = \app\admin\model\Promotion::where('status', 1)
            ->select();

        $all = array_map(function ($e) {
            $e->hasContent = strlen($e->content);
            $e->content = ''; //不传输content
            $e->image = url($e->image, '', false, true);
            return $e;
        }, $all);

        $this->success('ok', $all);
    }

    public function detail()
    {
        $id = $this->request->get('id');

        $data = \app\admin\model\Promotion::get($id);

        $this->success('ok', ['content' => $data->content]);
    }

}
